home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga CD-ROM Collection
/
Amiga CD-ROM Collection - Auge 4000 and Cactus and Demo Util.iso
/
auge4000
/
46
/
lib
/
amiga
/
chkabort.c
< prev
next >
Wrap
C/C++ Source or Header
|
1990-06-20
|
1KB
|
71 lines
/*
* BREAK.C
*
* (c)Copyright 1990, Matthew Dillon, All Rights Reserved
*
* Internal routine to check for ^C. NOTE, ^C is cleared before we
* write ^C\n because write itself calls chkabort().
*/
#include <exec/types.h>
#include <exec/tasks.h>
#include <exec/execbase.h>
#include <libraries/dos.h>
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
typedef int (*fptr)();
static int brk();
/*
* _SigIntFunc() is set by signal() if SIGINT is something other than the
* default. The reason for this is so the signal code is not included in
* the executable unless explicitly called.
*/
extern struct ExecBase *SysBase;
static int (*_BrkFunc)() = brk;
void (*_SigIntFunc)(int);
void
chkabort()
{
struct Task *task = SysBase->ThisTask;
if (task->tc_SigRecvd & SIGBREAKF_CTRL_C) {
SetSignal(0, SIGBREAKF_CTRL_C);
if ((*_BrkFunc)()) {
write(2, "^C\n", 3);
exit(EXIT_FAILURE);
}
}
}
static int
brk()
{
if (_SigIntFunc) {
(*_SigIntFunc)(SIGINT); /* func might exit */
return(0); /* do not exit */
}
return(1);
}
fptr
onbreak(func)
fptr func;
{
fptr old = _BrkFunc;
if (func == NULL) {
_BrkFunc = brk;
} else {
_BrkFunc = func;
}
return(old);
}